import VueRouter from "vue-router";
import HomeTest from "../page/home.vue";
import AboutTest from "../page/about.vue";
import MessageTest from "../page/message.vue";
import NewsTest from "../page/news.vue";
import DetailTest from "../page/detail.vue";
const router = new VueRouter({
    routes:[
        {
            path:"/about",
            name:"guanyu",
            component:AboutTest,
            meta:{
                title:"about关于",
                isAuto:true
            },
        },
            {
                path:"/home",
                name:"zhuye",
                component:HomeTest,
                meta:{
                     title:"home标题"
                },
                children:[
                    {
                        path:"message", 
                        name:"message",
                        component:MessageTest,
                        meta:{
                            title:"message标题"
                        },
                        children:[
                            {
                                name:"xiangqing",
                                path:"detail/:id/:title",
                                component:DetailTest,
                                props($route){
                                    return{
                                        id:$route.query.id,
                                        title:$route.query.title
                                    }
                                },
                                meta:{
                                    isAuto:true,
                                    title:"消息"
                                }
                            }
                        ]
                    },
                    {
                        path:"news",
                        name:"xiaoxi",
                        component:NewsTest,
                        meta:{
                            isAuto:true,
                            title:"消息"
                        }
                    }
                ]
            }, 
    ]
})
//在每一次路由切换之前都调用一个函数
router.beforeEach((to,from,next)=>{
    console.log(to,from)
    console.log('@@@@@@@@')
    next()
//     console.log(to)
//     console.log(from)
//     console.log(next)
//     if(to.meta.isAuto){
// if(localStorage.getItem("name")==='zc'){
//     next()
// }
//     else{
//     alert("请先登录")
// }
//     }else{
       
//         next()
//     }
//     if(to.name==='xiaoxi'||to.name==='message'){
//         if(localStorage.getItem("name")==='zc'){
//             next()
//         }else{
//             alert("请先登录")
//         }
//     }else{
//         next()
//     }

})
router.afterEach((to,from)=>{
    console.log(to,from)
    console.log('############')
    // console.log(to)
    // console.log(from)
    // document.title=to.meta.title
})
export default router